import datetime
import numpy as np
import pandas as pd


def datetime64_2_datetime(input):
    return input.astype(datetime.datetime)


def datetime_2_datetime64(input):
    return np.datetime64(input)


def timestamp_f_2_str_f(input:pd.Series, format_1='%Y-%m-%d %H:%M:%S%z', format_2='%Y-%m-%d'):
    """
    timestamp format to timestamp and timestamp format to str
    :param input:
    :param format_1:
    :param format_2:
    :return:
    """
    # kdatas['bob'] = pd.to_datetime(kdatas['bob'], format='%Y-%m-%d %H:%M:%S%z')
    # kdatas['bob'] = kdatas['bob'].dt.strftime('%Y-%m-%d')

    _input = input.copy()
    _input = pd.to_datetime(_input, format=format_1)
    _input = _input.dt.strftime(format_2)
    return _input


def str_2_timestamp(input, format='%Y-%m-%d'):
    return pd.to_datetime(input, format=format)

def timestamp_2_str(input, format='%Y-%m-%d'):
    return input.dt.strftime(format)

def get_today():
    today = datetime.datetime.now()
    print(today.strftime("%Y-%m-%d"))
    return today, today.strftime("%Y-%m-%d")


def get_yesterday():
    today, _ = get_today()
    yesterday = today - datetime.timedelta(days=1)
    return yesterday, yesterday.strftime("%Y-%m-%d")


def get_tomorrow():
    today, _ = get_today()
    tomorrow = today + datetime.timedelta(days=1)
    return tomorrow, tomorrow.strftime("%Y-%m-%d")


def compare_time(target='17:30', src_time='17:30'):
    target_time = datetime.datetime.strptime(target, "%H:%M").time()
    src_time = datetime.datetime.strptime(src_time, "%H:%M").time()
    # 检查是否超过17:30
    if src_time > target_time:
        print(f"当前时间已经超过{target}")
        return True
    else:
        print(f"当前时间未超过{target}")

    return False

def extend_17_30():
    today, today_str = get_today()
    yesterday, yesterday_str = get_yesterday()
    # print(today_str)
    # print(yesterday_str)
    if compare_time(src_time=datetime.datetime.now().time().strftime("%H:%M")):
        return today_str
    else:
        return yesterday_str


if __name__ == '__main__':
    # 1. 创建 target = datetime.datetime 对象
    # 2. target.strptime("17:30", "%H:%M") -> 通过字符串解析，然后构造出datetime对象 string parse to datetime
    # 3. target.time() -> 返回时区
    # 4. datetime.timedelta(days=1) 这是一个delta Δ 这里创建了一天
    # 5. 通过 datetime.datetime.strftime(time1, '%Y@%m@%d %H:%M') 把time1 格式化输出成字符串

    pass
















